package com.gopay.common.event.store;

import java.util.Collection;
import java.util.concurrent.Callable;

import com.gopay.common.datasource.DBType;
import com.gopay.common.datasource.DbContextHolder;
import com.gopay.common.domain.report.Event;
import com.gopay.common.report.dao.MqEventInfoDAO;

/**
 * 事件存储Task
 * 
 * @EventStoreTask.java
 * @author fanghw
 * @2015年6月9日 上午11:45:52 www.gopay.com.cn Inc.All rights reserved.
 */
public class EventStoreTask implements Callable<Boolean> {
    private Collection<Event> eventList;
    private MqEventInfoDAO mqEventInfoDAO;

    public EventStoreTask(Collection<Event> eventList, MqEventInfoDAO mqEventInfoDAO) {
        this.eventList = eventList;
        this.mqEventInfoDAO = mqEventInfoDAO;
    }

    @Override
    public Boolean call() throws Exception {
        DbContextHolder.setDbType(DBType.DS_REPORT.value);
        
        for (Event event : eventList) {
            mqEventInfoDAO.save(event);
        }

        return true;
    }

}
